package com.csii.mobilebanking.user;

import com.csii.mobilebanking.R;

import android.content.Context;
import android.graphics.drawable.ColorDrawable;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.LinearLayout;
import android.widget.PopupWindow;
import android.widget.RelativeLayout;
import android.widget.TextView;

/**
 * 实现拉下选择
 * 
 * @author Administrator
 * 
 */
public class LoginPopuWindow {

	public PopupWindow pw;
	public Context mContext;
	public View mContentView;
	public LinearLayout mLayout;

	public String mId;
	public String[] mExpandIds = new String[] { "用户名", "手机号" };
	private TextView mTextView;

	public LoginPopuWindow(Context context, View contentView,
			TextView tv_login_type) {
		mContext = context;
		mContentView = contentView;
		mTextView = tv_login_type;
		pw = new PopupWindow(mContext);
		pw.setBackgroundDrawable(new ColorDrawable(R.color.alpha_00));
		pw.getBackground().setAlpha(255);//不透明
		pw.setWidth(-2);
		pw.setHeight(-2);
		pw.setOutsideTouchable(true);//外部可以点击
		pw.setFocusable(true);

		init();
	}

	private void init() {
		mLayout = (LinearLayout) LayoutInflater.from(mContext).inflate(
				R.layout.hwzj_grouplist, null);
		for (int i = 0; i < mExpandIds.length; i++) {
			View view = (RelativeLayout) LayoutInflater.from(mContext).inflate(
					R.layout.hwzj_grouplist_item, null);
			TextView item1 = (TextView) view.findViewById(R.id.item1);
			final String item = mExpandIds[i];

			item1.setText(item);
			item1.setOnClickListener(new OnClickListener() {
				@Override
				public void onClick(View v) {
					if (pw != null && pw.isShowing()) {
						pw.dismiss();
					}
					if (item.equals(mExpandIds[0])) {
						GlobalCache.LOGIN_TYPE = GlobalConstant.LOGIN_USERNAME;
					} else if (item.equals(mExpandIds[1])) {
						GlobalCache.LOGIN_TYPE = GlobalConstant.LOGIN_PHONENUMBER;
					}
					mTextView.setText(item);// 赋值
//					mContext.exchangeInputtype();
				}
			});
			mLayout.addView(view);
		}
		pw.setContentView(mLayout);

		int xoff = -(int) (DisplayXValuesUtil.DipToPx(mContext, 25));
		int yoff = -(int) (DisplayXValuesUtil.DipToPx(mContext, 10));
		pw.showAsDropDown(mContentView, xoff, -yoff);
	}
}
